package com.zt.eb.web;

import com.zt.eb.mode.EbNews;
import com.zt.eb.mode.EbProduct;
import com.zt.eb.mode.EbProductCategory;
import com.zt.eb.service.EbProductCategorySercie;
import com.zt.eb.service.EbProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;


@Controller     //迎宾证
@RequestMapping("/front")       //工号

//用来迎接数据
public class IndexController {

    @Autowired     //service层的对象
    private EbProductService ebProductService;

    @Autowired
    private com.wc.eb.service.EbNewsService ebNewsService;

    @Autowired
    private EbProductCategorySercie ebProductCategorySercie;


    //行为       用来返回首页的数据(model)和视图(view)，把数据进行渲染
    @RequestMapping("/index")   //返回前端首页的数据和视图              //默认值为页面的第一页，每页有8条数据
    public String index(Model model,
                        @RequestParam(value = "pSize" ,defaultValue="1")Integer pSize,
                        @RequestParam (value = "pageSize",defaultValue = "8")Integer pageSize)
    {
        //1调用service层查询分页的商品信息
        List<EbProduct> ebProductList =ebProductService.selectList(pSize,pageSize);  //对于默认首页一般都为首页默认

        //2调用service层查询分页的新闻信息
        List<EbNews> ebNewsList = ebNewsService.selectList(1, 7);
        //ebProductService
        //3调用service层查询分页的分类信息
        Map<String, List<EbProductCategory>> categoryMap = ebProductCategorySercie.selectBigAndSmallCate();


        //4将数据绑定在model中     //用键值对的形式进行绑定数据
        model.addAttribute("ebProductList",ebProductList);
        model.addAttribute("ebNewsList",ebNewsList);
        model.addAttribute("categoryMap",categoryMap);

        //5 返回视图（html）
        return "index";  //templates/index.html




    }

}
